﻿using System;
using Microsoft.Xna.Framework;

namespace SaveTheQueen.Actions
{
    /// <summary>
    /// Action that interpolate 2 values, thus a vector2.
    /// <remarks>Same as 2 blend actions, one for X and one for Y of a vector2.</remarks>
    /// </summary>
    public class Vector2BlendAction : BaseAction<Vector2>
    {
        private InterpolationMethod method;
        /// <summary>
        /// Method of the blend.
        /// </summary>
        public InterpolationMethod Method
        {
            get { return method; }
            set { method = value; }
        }

        /// <summary>
        /// Creates a new instance of the VectorBlendAction.
        /// </summary>
        /// <param name="game"></param>
        public Vector2BlendAction(Game game)
            : base(game)
        {
            method = InterpolationMethod.Sine;
        }

        protected override void Process(GameTime gameTime)
        {
            Vector2 delta = Goal - Input;
            if (method == InterpolationMethod.Sine)
            {
                Actual = Input + delta * (float)Math.Sin((elapsedTime / time) * 1.57079f);
            }
            else if (method == InterpolationMethod.Linear)
            {
                Actual = Input + delta * (elapsedTime / time);
            }
            else
            {
                throw new Exception("Invalid interpolation method. " + method.ToString());
            }
        }
    }
}
